package com.car.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

public class LogUtil {
	/**
	 * @date 2013年8月26日 排序
	 */
	public static String[] sort(int beginNum, HashMap<String, Integer> requestMap) {
		if(requestMap==null||requestMap.size()==0)return null;
		Set<String> keys = requestMap.keySet();
		List<String> requestList = new ArrayList<String>(keys);
		if (keys == null || keys.size() <= 0) {
			return null;
		}
		if (beginNum < 0 || beginNum > keys.size()) {
			beginNum = keys.size();
		}
		String[] data = new String[beginNum];
		for (int i = 0; i < beginNum; i++) {
			data[i] = (String) requestList.get(i);
		}
		HeapSort.buildHeap(data, data.length - 1, requestMap);
		for (int i = beginNum; i < requestList.size(); i++) {
			if (requestMap.get(data[0]) < requestMap.get(requestList.get(i))) {
				data[0] = (String) requestList.get(i);
				HeapSort.buildHeap(data, data.length - 1, requestMap);
			}
		}
		HeapSort.heapSort(data, requestMap);
		return data;
	}
}
